package au.com.handsunited.service.impl;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import au.com.handsunited.dao.ServiceCategoryDAO;
import au.com.handsunited.model.servicecategory.ServiceCategory;
import au.com.handsunited.service.ServiceCategoryService;

/**
 * @author arunc
 *
 */
public class ServiceCategoryServiceImpl implements ServiceCategoryService {

	private ServiceCategoryDAO serviceCategoryDAO;


	private static Logger logger = LoggerFactory.getLogger(ServiceCategoryServiceImpl.class);



	/**
	 *
	 */
	public ServiceCategoryServiceImpl() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param serviceCategoryDAO
	 */
	public ServiceCategoryServiceImpl(ServiceCategoryDAO serviceCategoryDAO) {
		super();
		this.serviceCategoryDAO = serviceCategoryDAO;
	}

	/**
	 * @see au.com.handsunited.service.ServiceCategoryService#createServiceCategory(au.com.handsunited.model.servicecategory.ServiceCategory)
	 */
	@Override
	public ServiceCategory createServiceCategory(ServiceCategory serviceCategory) {
		return serviceCategoryDAO.create(serviceCategory);
	}

	/**
	 * @see au.com.handsunited.service.ServiceCategoryService#deleteServiceCategory(au.com.handsunited.model.servicecategory.ServiceCategory)
	 */
	@Override
	public void deleteServiceCategory(ServiceCategory serviceCategory) {
		serviceCategoryDAO.delete(serviceCategory);

	}

	/**
	 * @see au.com.handsunited.service.ServiceCategoryService#getAllServiceCategories()
	 */
	@Override
	public List<ServiceCategory> getAllServiceCategories() {
		return serviceCategoryDAO.getAllServiceCategories();
	}

	/**
	 * @see au.com.handsunited.service.ServiceCategoryService#getServiceCategory(java.lang.String)
	 */
	@Override
	public ServiceCategory getServiceCategory(String id) {
		return getServiceCategory(Long.parseLong(id));
	}

	/**
	 * @see au.com.handsunited.service.ServiceCategoryService#getServiceCategory(java.lang.Long)
	 */
	@Override
	public ServiceCategory getServiceCategory(Long id) {
		return serviceCategoryDAO.read(id);
	}

	/**
	 * @see au.com.handsunited.service.ServiceCategoryService#updateServiceCategory(au.com.handsunited.model.servicecategory.ServiceCategory)
	 */
	@Override
	public ServiceCategory updateServiceCategory(ServiceCategory serviceCategory) {
		return serviceCategoryDAO.update(serviceCategory);
	}

	/**
	 * @see au.com.handsunited.service.ServiceCategoryService#getServiceCategoryMap()
	 */
	@Override
	public Map<Long, ServiceCategory> getServiceCategoryMap() {

		Map<Long, ServiceCategory> serviceCategoryMap = new TreeMap<Long, ServiceCategory>();
		for (ServiceCategory serviceCategory : getAllServiceCategories()) {
			serviceCategoryMap.put(serviceCategory.getId(), serviceCategory);
		}
		return serviceCategoryMap;
	}



}
